<?php
/**
 * Description of comunas
 *
 * @author jastudic
 */
class Moneda extends Controller {

    function Moneda() {
        parent::Controller();
        
        $this->load->library("autenticacion");
        $this->load->library("templator");
        $this->load->helper('form');
	$this->load->helper('language'); 
	$this->load->helper('url');
        $this->load->model("buscadores/conversiones_monetarias_model");
	$this->lang->load('db_fields', 'english'); // This is the language file
    }

    function index($limit = FALSE, $offset = 0){
        $this->_security_check();
        $viewName = "mantenedores/mantenedor_moneda";
	$viewData = array();
        
	$this->templator->template_sin_buscador($viewName, $viewData);
        
    }
    
    function editar_moneda( $id = false )
    {
        $this->_security_check();
        
        $this->load->library('form_validation');
        
        switch ( $_SERVER ['REQUEST_METHOD'] ){
            case 'GET':
                
                echo "METODO GET";
                break;
            case 'POST':
                /* we set the rules */
                /* dont forget to edit these */
                $this->form_validation->set_rules( 'moneda_uf', lang('moneda_uf'), 'required|max_length[6]|is_natural' );
                $this->form_validation->set_rules( 'moneda_dolar', lang('moneda_dolar'), 'required|max_length[6]|is_natural' );

                $data_post['monedaUF'] = strtoupper($this->input->post("moneda_uf"));
                $data_post['monedaDOLAR'] = strtoupper($this->input->post('moneda_dolar'));
                
                $this->form_validation->set_message('required', 'Debe introducir el campo %s');
                $this->form_validation->set_message('max_length', 'El campo %s debe ser de maximo %s carácteres');
                $this->form_validation->set_message('is_natural', 'el campo %s es numerico');
                
                if ($this->form_validation->run() == FALSE) {
                
                }else{
                    $this->conversiones_monetarias_model->editar_monedas( $data_post );
                }

                
                
                redirect('moneda/index');

                break;
            }
    }
    
    private function _security_check() {
        $isLoggedin = $this->autenticacion->logged_in();
        $isAdmin = $this->autenticacion->is_admin();

        //descomentar para activar la seguridad
        if ( ! $isLoggedin ){

            redirect("home_principal");
            exit(); //termina con la redireccion

        }
    }    

}

?>
